import urllib.request
import urllib.parse
import ssl

ssl._create_default_https_context = ssl._create_unverified_context
# 因为中文会默认转换为 unicode编码格式所我们需要转换一下
"""
url = 'https://www.baidu.com/s?wd='   # %E5%91%A8%E6%9D%B0%E4%BC%A6  周杰伦

name = urllib.parse.quote('周杰伦')
url = url + name

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36"
}

request = urllib.request.Request(url=url, headers=headers)

content = urllib.request.urlopen(request)
print(content)
"""

# 如果有多个参数我们就使用 urlencode转换
data = {
    'wd': '周杰伦',
    'sex': '男',
    'location': '中国台湾省'
}
new_data = urllib.parse.urlencode(data)
print(new_data)
